//
//  MyViewController.swift
//  TravelNotes
//
//  Created by 千锋 on 16/8/15.
//  Copyright © 2016年 胡光健. All rights reserved.
//

import UIKit

class MyViewController: RootViewController, UITableViewDataSource, UITableViewDelegate {

    var tableView = UITableView()
    var headerImageView = UIImageView()
    let imageOriginaHeight: CGFloat = 150
    var buttonArray = [UIButton]()
    
    let unselectedImageArray = ["youji11", "shoucang1", "xihuan1"]
    let selectedImageArray = ["youji22", "shoucang2", "xihuan2"]
    var dataArray = NSArray()
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        for i in 0..<buttonArray.count {
            let btn = buttonArray[i]
            if btn == buttonArray.first {
                btn.selected = true
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        self.titleLabel?.text = "我的旅游"
        
        createUI()
    }
    func createUI() {
        tableView = UITableView(frame: CGRectMake(0, 0, screenWidth, screenHeight), style: .Plain)
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.view.addSubview(tableView)
        self.tableView.tableFooterView = UIView()
        
        let headerView = UIView(frame: CGRectMake(0,0,screenWidth,screenHeight / 3))
        self.view.addSubview(headerView)
        
        headerImageView = Factory.createImageViewWith(CGRectMake(0, 0, screenWidth, imageOriginaHeight), imageName: "22")
        headerView.addSubview(headerImageView)
        self.tableView.tableHeaderView = headerView
        
        for i in 0..<3 {
            let button = UIButton(type: .Custom)
            button.frame = CGRectMake(CGFloat(i) * screenWidth / 3 , imageOriginaHeight, screenWidth / 3, 60)
            button.setImage(UIImage(named: unselectedImageArray[i]), forState: .Normal)
            button.setImage(UIImage(named: selectedImageArray[i]), forState: .Selected)
            button.addTarget(self, action: "backButtonClicked:", forControlEvents: .TouchUpInside)
            button.tag = 10 + i
            headerView.addSubview(button)
            buttonArray.append(button)
        }
        
        tableView.registerNib(UINib(nibName: "MyCell", bundle: nil), forCellReuseIdentifier: "myCell")
    }
    
    func backButtonClicked(button: UIButton) {
        for bu in buttonArray {
            bu.selected = false
        }
        button.selected = true
        if button.tag == 0 {
            
        }
        else if button.tag == 1 {
            
            
        }
        else if button.tag == 2 {
            
        }
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as! MyCell
        
        if dataArray.count > 0 {
            
        }
        return cell
    }
}
